<?php

namespace App\Trip\Orders\BookOrders\Params\Plane;

use App\Trip\Enums\OrderBusiness;
use App\Trip\Enums\Plane\PlaneProviders;
use App\Trip\Enums\TripTypes;
use App\Trip\Orders\BookOrders\Params\AbstractOrderParam\AbstractOrderParam;
use Illuminate\Support\Facades\Validator;
use InvalidArgumentException;

class BookPlaneOrderParam extends AbstractOrderParam
{
    public array $order_data;

    public function __construct(array $param)
    {
        $this->order_data = $param;
        if (!isset($this->trip_id)) {
            $this->order_data['trip_id'] = generate_order_id(TripTypes::PLANE, OrderBusiness::ORDER);
        }
    }


    public function getOrder(): array
    {
        $validator = Validator::make($this->order_data, []);
        if ($validator->fails()) {
            throw new InvalidArgumentException($validator->errors()->first());
        }
        return $this->order_data;
    }

    public function OrderService(): string
    {
        return PlaneProviders::from($this->provider)->value;
    }

    // 飞机没啥用
    public function getSelectSeat(): array
    {
        return [];
    }

    public function isSnapUp(): bool
    {
        return false;
    }

    /**
     * 获取外部单号
     *
     * @return string
     */
    public function getOutOrderSn(): string
    {
        return $this->getTripId();
    }

    public function getTripId(): string
    {
        return $this->trip_id;
    }


}